package com.appwoo.txtws.activity;

import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.appwoo.txtws.adapter.ListViewCreator;
import com.appwoo.txtws.adapter.Page;
import com.appwoo.txtws.adapter.SimpleListAdapter;
import com.appwoo.txtws.app.App;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.AppInfo;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.wheel.widget.PageListView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class RecomedForChildActivity extends AppActivity
{
  public static final String ACTION_Del_Data = "delData";
  public static List<AppInfo> appDel;
  public static AppInfo appFromdown;
  private SimpleListAdapter<AppInfo> adapter;
  private List<AppInfo> appInfos;
  private Boolean isFoot = Boolean.valueOf(false);
  private LinearLayout llEmpty;
  private PageListView lvList;
  private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver()
  {
    public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
    {
      if (paramAnonymousIntent.getAction().equals("delData"));
      for (int i = 0; ; i++)
      {
        if (i >= RecomedForChildActivity.appDel.size())
        {
          RecomedForChildActivity.appDel.clear();
          RecomedForChildActivity.this.adapter.notifyDataSetChanged();
          return;
        }
        File localFile = new File(((AppInfo)RecomedForChildActivity.appDel.get(i)).getFilePath());
        if (localFile.exists())
        {
          localFile.delete();
          RecomedForChildActivity.this.page.remove((AppInfo)RecomedForChildActivity.appDel.get(i));
        }
      }
    }
  };
  private Page<AppInfo> page;
  private ProgressBar pb;
  private PackageManager pm;
  private TextView tvEmpty;

  private void delbuildDialog(Context paramContext, final AppInfo paramAppInfo)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
    localBuilder.setIcon(2130837508);
    localBuilder.setTitle(getString(2131428058));
    localBuilder.setPositiveButton(getString(2131427513), new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        File localFile = new File(paramAppInfo.getFilePath());
        if (localFile.exists())
          localFile.delete();
        RecomedForChildActivity.this.page.remove(RecomedForChildActivity.appFromdown);
        RecomedForChildActivity.this.adapter.notifyDataSetChanged();
      }
    });
    localBuilder.setNegativeButton(getString(2131427514), new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
      }
    });
    localBuilder.show();
  }

  private void initView()
  {
    this.appInfos = new ArrayList();
    appDel = new ArrayList();
    this.page = new Page();
    this.page.setPageSize(200);
    this.lvList = ((PageListView)findViewById(2131492985));
    this.pm = getPackageManager();
    this.adapter = new SimpleListAdapter(this.page.getEntries(), new ListViewCreator()
    {
      public View createView(final AppInfo paramAnonymousAppInfo, View paramAnonymousView, int paramAnonymousInt)
      {
        if (paramAnonymousView == null)
          paramAnonymousView = App.getLayoutInflater().inflate(2130903118, null);
        ((TextView)paramAnonymousView.findViewById(2131493155)).setText(paramAnonymousAppInfo.getAppLabel());
        ((ImageView)paramAnonymousView.findViewById(2131493154)).setImageDrawable(paramAnonymousAppInfo.getAppIcon());
        CheckBox localCheckBox = (CheckBox)paramAnonymousView.findViewById(2131493011);
        localCheckBox.setChecked(paramAnonymousAppInfo.getIsCheck());
        ((Button)paramAnonymousView.findViewById(2131493156)).setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramAnonymous2View)
          {
            RecomedForChildActivity.appFromdown = paramAnonymousAppInfo;
            if (new File(paramAnonymousAppInfo.getFilePath()).exists())
              RecomedForChildActivity.this.delbuildDialog(RecomedForChildActivity.this, paramAnonymousAppInfo);
          }
        });
        localCheckBox.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramAnonymous2View)
          {
            RecomedForChildActivity.appFromdown = paramAnonymousAppInfo;
            if (((CheckBox)paramAnonymous2View).isChecked())
            {
              RecomedForChildActivity.appFromdown.setIsCheck(true);
              if (!RecomedForChildActivity.appDel.contains(paramAnonymousAppInfo))
                RecomedForChildActivity.appDel.add(paramAnonymousAppInfo);
            }
            do
            {
              return;
              RecomedForChildActivity.appFromdown.setIsCheck(false);
            }
            while (!RecomedForChildActivity.appDel.contains(paramAnonymousAppInfo));
            RecomedForChildActivity.appDel.remove(paramAnonymousAppInfo);
          }
        });
        return paramAnonymousView;
      }
    });
    this.lvList.setAdapter(this.adapter);
    addOperation(new DataTask().execute(new String[] { "" }));
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903146);
    initView();
    registerBoradcastReceiver();
  }

  public void onDestroy()
  {
    super.onDestroy();
    try
    {
      unregisterReceiver(this.mBroadcastReceiver);
      return;
    }
    catch (Exception localException)
    {
    }
  }

  protected void onResume()
  {
    super.onResume();
  }

  public void registerBoradcastReceiver()
  {
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction("delData");
    registerReceiver(this.mBroadcastReceiver, localIntentFilter);
  }

  class DataTask extends AsyncTask<String, String, String>
  {
    String param;

    DataTask()
    {
    }

    private void searchFiles(File paramFile)
    {
      int i;
      int j;
      try
      {
        File[] arrayOfFile = paramFile.listFiles();
        if (arrayOfFile.length > 0)
        {
          i = arrayOfFile.length;
          j = 0;
          break label210;
          File localFile = arrayOfFile[j];
          if (localFile.isDirectory())
          {
            String[] arrayOfString = new String[1];
            arrayOfString[0] = localFile.getPath();
            publishProgress(arrayOfString);
            searchFiles(localFile);
            RecomedForChildActivity.this.logDebug("zhy 循环文件夹");
            if (!isCancelled())
              break label218;
          }
          else
          {
            RecomedForChildActivity.this.logDebug("zhy 循环文件");
            if (!isCancelled())
            {
              String str = localFile.getPath();
              if (!str.substring(1 + str.lastIndexOf("."), str.length()).toLowerCase().equals("apk"))
                break label218;
              PackageInfo localPackageInfo = RecomedForChildActivity.this.pm.getPackageArchiveInfo(str, 1);
              if ((localPackageInfo == null) || (localPackageInfo.packageName.equals("com.appwoo.txtws.activity")) || (localPackageInfo.packageName.equals("com.txtw.daemon")))
                break label218;
              RecomedForChildActivity.this.appInfos.add(Global.getApkFileInfo(RecomedForChildActivity.this, str));
            }
          }
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        return;
      }
      label210: 
      while (j >= i)
      {
        return;
        label218: j++;
      }
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      File localFile = new File(Environment.getExternalStorageDirectory().getPath());
      searchFiles(new File(Global.SOFTPATHMEMORY));
      searchFiles(localFile);
      return null;
    }

    protected void onPostExecute(String paramString)
    {
      RecomedForChildActivity.this.page.setEntries(RecomedForChildActivity.this.appInfos);
      RecomedForChildActivity.this.adapter.notifyDataSetChanged();
      RecomedForChildActivity.this.lvList.onLoadMoreComplete();
      RecomedForChildActivity.this.lvList.hideFotterMoreView();
      if (!RecomedForChildActivity.this.isFoot.booleanValue())
      {
        RecomedForChildActivity.this.llEmpty.setVisibility(8);
        RecomedForChildActivity.this.lvList.setVisibility(0);
        RecomedForChildActivity.this.isFoot = Boolean.valueOf(false);
      }
      super.onPostExecute(paramString);
    }

    protected void onPreExecute()
    {
      if (!RecomedForChildActivity.this.isFoot.booleanValue())
      {
        RecomedForChildActivity.this.llEmpty = ((LinearLayout)RecomedForChildActivity.this.findViewById(2131493266));
        RecomedForChildActivity.this.pb = ((ProgressBar)RecomedForChildActivity.this.findViewById(2131493215));
        RecomedForChildActivity.this.tvEmpty = ((TextView)RecomedForChildActivity.this.findViewById(2131493267));
        RecomedForChildActivity.this.tvEmpty.setText("加载中");
        RecomedForChildActivity.this.tvEmpty.setTextSize(16.0F);
        RecomedForChildActivity.this.llEmpty.setVisibility(0);
        RecomedForChildActivity.this.lvList.setVisibility(8);
      }
      super.onPreExecute();
    }

    protected void onProgressUpdate(String[] paramArrayOfString)
    {
      if (RecomedForChildActivity.this.tvEmpty != null)
        RecomedForChildActivity.this.tvEmpty.setText("加载中:" + paramArrayOfString[0]);
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.RecomedForChildActivity
 * JD-Core Version:    0.6.2
 */